package Hot100.twoSearch;

public class searchMatrix {
    public static void main(String[] args) {
        int[][] matrix = {{1},{0}};
        int target = 0;
        System.out.println(new searchMatrix().searchMatrix(matrix,target));
    }
    public boolean searchMatrix(int[][] matrix, int target) {
        int length = matrix.length,width = matrix[0].length;
        int right = length * width - 1,left = 0;
        if(length == 0 || width == 0)
            return false;
        int mid  = 0;
        while(right >= left){
            mid = (right + left) / 2;
            int row = mid / width;
            int col = mid % width;
            if(matrix[row][col] == target)
                return true;
            else if (matrix[row][col] > target) {
                right = mid - 1;
            }else {
                left = mid + 1;
            }
        }
        return false;
    }
}
